package com.school.controller.mall;

import com.school.common.Constants;
import com.school.common.IndexConfigTypeEnum;
import com.school.controller.vo.IndexCarouselVO;
import com.school.controller.vo.IndexCategoryVO;
import com.school.controller.vo.IndexConfigGoodsVO;
import com.school.service.IndexConfigService;
import com.school.service.CarouselService;
import com.school.service.GoodsCategoryService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;


import java.util.List;

import static com.school.common.IndexConfigTypeEnum.INDEX_GOODS_HOT;

@Controller
public class IndexController {

    @Autowired
    private IndexConfigService indexConfigService;

    @Autowired
    private CarouselService carouselService;

    @Autowired
    private GoodsCategoryService goodsCategoryService;

    @GetMapping({"/", "/index", "/index.html"})
    public String index(HttpServletRequest request) {
        List<IndexCategoryVO> categories = goodsCategoryService.getCategoriesForIndex();
        List<IndexCarouselVO> carousels = carouselService.getCarouselsForIndex(Constants.INDEX_CAROUSEL_NUMBER);
        List<IndexConfigGoodsVO> hotGoodses = indexConfigService.getConfigGoodsForIndex(IndexConfigTypeEnum.INDEX_GOODS_HOT.getType(), Constants.INDEX_GOODS_HOT_NUMBER);
        List<IndexConfigGoodsVO> newGoodses = indexConfigService.getConfigGoodsForIndex(IndexConfigTypeEnum.INDEX_GOODS_NEW.getType(), Constants.INDEX_GOODS_NEW_NUMBER);
        List<IndexConfigGoodsVO> recommendGoodses = indexConfigService.getConfigGoodsForIndex(IndexConfigTypeEnum.INDEX_GOODS_RECOMMOND.getType(), Constants.INDEX_GOODS_RECOMMOND_NUMBER);

        request.setAttribute("categories", categories);
        request.setAttribute("carousels", carousels);
        request.setAttribute("hotGoodses", hotGoodses);
        request.setAttribute("recommendGoodses", recommendGoodses);
        request.setAttribute("newGoodses", newGoodses);

        return "mall/index";
    }
}
